<#include "/main.ftl"/>
<@diamondNav/>
<body>
<div id="content" style="margin-left: 13%">
    <div style="margin-top: 5%;margin-left: 1%;width: 100%">
        <#if interfaceMockData.interfaceMockDataId??>
            <form action="/interfaceMockDataController/updateInterfaceMockData"
        <#else >
             <form action="/interfaceMockDataController/addInterfaceMockData"
        </#if> method="post" id="myForm" class="form-horizontal" >
        <div class="form-group">
            <div class="row">
                <div class="col-md-5">
                    <label class="control-label" for="">匹配数据</label>
                            <#switch Session.matchType>
                                <#case "keyValue">
                                        <div id="paramKeyDiv">
                                            <button type="button" class="btn btn-success" id="addParamButton">
                                                增加key
                                            </button>
                                            <#if interfaceMockData.matchData?? && interfaceMockData.matchData!=''>
                                                <@writeKeyValue interfaceMockData.matchData/>
                                            <#else >
                                                <input type="hidden" id="paramIndex" value="0">
                                            </#if>
                                        </div>
                                    <#break>
                                <#case  "jsonPath">
                                <#case  "xPath">
                                    <div id="paramKeyDiv">
                                            <button type="button" class="btn btn-success" id="addParamButton">
                                                增加${matchType!}表达式
                                            </button>
                                            前面表达式,后面值,例子:$.obj.id  1
                                            <#if interfaceMockData.matchData?? && interfaceMockData.matchData!=''>
                                                <@writeKeyValue interfaceMockData.matchData/>
                                            <#else >
                                                <input type="hidden" id="paramIndex" value="0">
                                            </#if>
                                        </div>
                                    <#break>
                                <#case  "custom">
                                    <div class="control-label">
                                    <span style="font-size: 20px">自定义脚本是不需要填写内容的，
                                                                    在自定义脚本的代码里面填写mock数据的Id即可
                                    </span>
                                    </div>
                                    <#break>
                                <#case  "noMatch">
                                    <span style="font-size: 20px">当前接口不需要任何匹配,直接填写mock数据即可
                                    </span>
                                    <#break>
                                <#default>
                            </#switch>
                </div>
                <div class="col-md-5">
                    <label class="control-label" for="mockData">mockData数据</label>
                    <textarea id="mockData" name="mockData" class="form-control"
                              style="min-height: 60%;max-width: 100%;min-width: 100%"
                               placeholder="mockData数据">
                        <#if interfaceMockData?? && interfaceMockData.mockData ??>${interfaceMockData.mockData!}</#if>
                    </textarea>
                 <#if interfaceMockData??>
                     <@spring.bind "interfaceMockData.mockData" />
                     <span style="color: red"> <@spring.showErrors ""/> </span>
                 </#if>

                </div>
            </div>
        </div>
        <div>
            <input type="hidden" name="matchData" id="matchData">
            <input name="interfaceMockId" id="interfaceMockId" type="hidden"
                   value="${Session.interfaceMockId}"/>
            <input type="hidden" name="matchType" value="${Session.matchType}">
            <input name="interfaceMockDataId" type="hidden"
                   value="<#if interfaceMockData?? && interfaceMockData.interfaceMockDataId ??>${interfaceMockData.interfaceMockDataId!}</#if>">
        </div>
        <div class="form-group">
            <div class="col-md-offset-2 col-md-10">
                <button type="button" class="btn btn-success " id="back">
                    返回
                </button>
                <button type="reset" class="btn btn-success ">
                    重置
                </button>
                <button type="submit" class="btn btn-success" onclick="oKeyValueUtil.writeParam()">
                    提交
                </button>
            </div>
        </div>
    </form>
    </div>
</div>
</body>

<script type="text/javascript">
    $(document).ready(function () {
        oKeyValueUtil = new KeyValueUtil();
        oKeyValueUtil.init($('#paramKeyDiv'), $("#addParamButton"), $("#matchData"));
    })
    $("#back").click(function () {
        // var interfaceMockId = $("#interfaceMockId").val();
        // var matchType = $("#matchType").val();
        window.location.href = "/interfaceMockDataController/interfaceMockDataPage?";
        // window.location.href = "/interfaceMockDataController/interfaceMockDataPage?interfaceMockId=" + interfaceMockId + "&matchType=" + matchType;
    })
</script>